Repository navigation
Walk sets of states instead of determinizing, add symmetric_difference - #28
Merged
Merged
Conversation
alexvbrdn
force-pushed
the
avoid-determinization
branch
from
November 19, 2026 18:21
2c16da9 to
ea0e939
Compare
equivalent, subset, cardinality and difference no longer determinize or complement their operands: they walk the sets of states a word can reach (bisimulation up to congruence for equivalent, antichains for subset). Two deterministic automata are compared with Hopcroft & Karp. has_intersection no longer builds the intersection, Term::is_finite looks for a cycle instead of counting, Term::is_total uses subset, and remove_state(s) no longer scan every state's transitions.
Since #11, `union_mut_nondegenerate` checks the state limit with `union_state_count_nondegenerate`, and only `test_heuristic` used `union_state_count_heuristic`, which added the degenerate cases and was kept in the `impl` behind `#[cfg(test)]`. It is now a helper of the tests module, and the remaining count is `union_state_count`.
`FastAutomaton::symmetric_difference`, `symmetric_difference_all` and `symmetric_difference_all_par`, and `Term::symmetric_difference`, built like `difference` without determinizing an operand. `difference` leaves out the pairs that reach no accept state as it builds its result. `SetTrie::has_subset_of` no longer recurses per state of a stored set, which overflowed the stack of a thread in `subset`. Regular expressions: concatenation folds in place, in time linear in the number of expressions, and parsing checks the timeout as it concatenates; `Term::union` of regular expressions respects the timeout; `is_empty`, `is_empty_string` and `length` are exact on expressions that are not simplified. Rewrites the documentation of the public API.
alexvbrdn
force-pushed
the
avoid-determinization
branch
from
November 20, 2026 19:19
5dc3db4 to
d17c4c4
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this changes
Set operations without determinization
equivalent,subset,cardinalityanddifferenceno longer determinize or complement their operands. Instead they work on the sets of states a word can reach in each automaton, and only build the sets that are actually reached.equivalent: bisimulation up to congruence (HKC, Bonchi & Pous, POPL 2013). Two deterministic automata are compared state by state with Hopcroft & Karp (1971).subset: antichains (De Wulf, Doyen, Henzinger & Raskin, CAV 2006).cardinality: on a non-deterministic automaton, strings are counted per set of states, so a string with several paths is counted once. It returnsBigIntegeras soon as one set's count overflows.difference: each state of the result pairs a state of the minuend with the set of subtrahend states the same word reaches. States that can't reach an accept state are left out as the result is built.has_intersectionno longer builds the intersection.Term::is_finitelooks for a cycle instead of counting.Term::is_totalusessubset.remove_state/remove_statesno longer scan every state's transitions.Behaviour change: when the execution profile disables implicit determinization,
FastAutomaton::equivalent,subset,cardinalityanddifferencenow accept non-deterministic automata instead of returningDeterministicAutomatonRequired. Onlyminimizeandcomplementstill determinize implicitly.New: symmetric difference
FastAutomaton::symmetric_difference: the strings exactly one of two automata accepts. Neither operand is determinized, and the result is deterministic when both are.FastAutomaton::symmetric_difference_all/symmetric_difference_all_par, andTerm::symmetric_difference: the strings an odd number of the automata accept. The automata are walked together rather than two by two._all_parneeds theparallelfeature and is absent onwasm.Fixes
RegularExpression::concat_all,simplifyandTerm::concatused to copy everything accumulated so far for each expression added. A pattern of 5,000 groups now parses in 10 ms instead of 1.3 s, and the parser checks the timeout as it builds a concatenation.Term::unionrespects the timeout for terms backed by regular expressions.RegularExpression::is_empty/is_empty_stringare exact on expressions that aren't simplified (for example()*parsed without simplification), and so are the matchingTermmethods.lengthreturns a maximum of 0 for an unbounded repetition of the empty string (()*,()+,(){2,}).subsetno longer overflows the stack on very large sets of states (SetTrie::has_subset_ofis iterative).Internal
implintounion.rs's tests module.symmetric_differenceis added to the README's method table.Performance
On the new benches in
benches/operations.rs:equivalent/subset: 2 to 20 times faster, and about 100 times faster where most pairs are skipped.difference: up to 3 times faster, and about 170 times faster when the minuend reaches few of the subtrahend's sets.has_intersection: about 3 times faster.minimize: 17% faster on the large pattern.Checklist
cargo fmt --all --checkandcargo clippy --all-targets -- -D warningspasscargo testandcargo test --no-default-featurespassCHANGELOG.mdis updated under## [Unreleased]